class Document < ActiveRecord::Base 
  belongs_to :document_category
  has_many :document_version, :dependent => :destroy, :order => "version desc"

  validates_presence_of(:title,:document_category_id,:updated_by)

  def current_version
    d = nil
    document_version.each{|doc| d = doc if doc.is_current == true}
    d = document_version[0] if d.nil?
    d
  end
end
